/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basecontrollcenter.gui.elements;

import basecontrollcenter.elements.AutoSizeLabel;
import basecontrollcenter.gui.moduls.BoxedJPane;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author rbs
 */
public class ClockComponent extends BoxedJPane {

    private AutoSizeLabel timeLabel;
    private AutoSizeLabel dateLabel;
    
    public ClockComponent() {
        super("Uhrzeit");
        
        setMinimumSize(new Dimension(100, 100));
        setPreferredSize(new Dimension(100, 100));
        
        setLayout(new BorderLayout());
        
        timeLabel = new AutoSizeLabel("--:--:--");
        dateLabel = new AutoSizeLabel("--.--.----");
        
        final Date date = new Date();
        final SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("HH:mm:ss");
        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy");
        Timer timer = new Timer(0, new ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                date.setTime(System.currentTimeMillis());
                timeLabel.setText(simpleTimeFormat.format(date));
                dateLabel.setText(simpleDateFormat.format(date));
            }
        });
        timer.setRepeats(true);
        timer.start();
        
        dateLabel.setMinimumSize(new Dimension(100, 30));
        dateLabel.setPreferredSize(new Dimension(100, 30));
        dateLabel.center();
        
        timeLabel.center();
        
        add(timeLabel, BorderLayout.CENTER);
        add(dateLabel, BorderLayout.SOUTH);
    }
    
    
}
